<?php

require DOCMENT_ROOT.'/Framework/controller.class.php';
class newController extends controller{
    public function __construct(){
        parent::header();
        parent::smartyAction("Admin");
    }
    //删除
    public function newdelete(){
        $id=$_GET["id"];
        //调取数据
    require DOCMENT_ROOT."/Application/Admin/model/newModel.class.php";
        $newModel=new newModel();
        $result=$newModel->deleteOne($id);
        if($result==true){
            echo "删除成功";
        }else{
             echo "删除失败";
        }
    }
    //修改
    public function newupdateSmarty(){
        $id=$_GET["id"];
        require DOCMENT_ROOT."/Application/Admin/model/newModel.class.php";
        $newModel=new newModel();
        $arr=$newModel->newselect($id);
        $this->smarty->assign("arr",$arr[0]);
        $this->smarty->display("newupdate.html");    
        }
    public function newupdate(){
        $id=$_POST["id"];
        $title=$_POST["title"];
        $content=$_POST["content"];
        //调取数据
       require DOCMENT_ROOT."/Application/Admin/model/newModel.class.php";
        $newModel=new newModel();
        $arr=$newModel->updateOne($title,$content,$id);
        
    }
    public function checktitle(){
        $title=$_GET["title"];
        //验证数据
        require DOCMENT_ROOT."/Application/Admin/model/newModel.class.php";
        $newModel=new newModel();
        $where="title='$title'";
        $result=$newModel->checkContent($where);
        echo $result;
    }
    //列表
    public function newlist(){
        //调取数据
        require DOCMENT_ROOT."/Application/Admin/model/newModel.class.php";
        $newModel=new newModel();
        $num=2;
        $page=isset($_GET["page"])?$_GET["page"]:1;  //判断是否为空，默认为1
        $start = ($page-1)*$num; //开始的条数
        $arr = $newModel->newList("add_time asc", $num, $start); //调用model文件
        //总条数
        $count = $newModel->newCount();//调用model文件
        //总页数
        $pageCount = ceil($count/$num);
        //调取展示页面
        $this->smarty->assign("list", $arr);
        $this->smarty->assign("page", $page);
        $this->smarty->assign("pagecount", $pageCount);
        
        //调取展示页面
        $this->smarty->assign("list", $arr);//传值（新值，原来值）
        $this->smarty->display("newlist.html"); //定义合并文件
    }
    
}


